  layui.config({
        base: './../../layui/lay/modules/'
    });

		
		
//从1970年开始的毫秒数然后截取10位变成 从1970年开始的秒数
function timest() {
  var tmp = Date.parse( new Date() ).toString();
  tmp = tmp.substr(0,10);
  return tmp;
}




layui.use(['element','flow','form','layer','layedit','laydate','upload','notice'],function(){
	var flow = layui.flow;
	
	

    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        laypage = layui.laypage,
        upload = layui.upload,
        layedit = layui.layedit,
        laydate = layui.laydate,
        $ = layui.jquery;


   
    form.on("submit(save_book)",function(data){
       var types=new Array(data.field.length);
       var i = 0;
       for(var key in data.field){
				 var pdata={
					"categoryName":key,
				 }
				 types[i]=pdata;
				 i++;
       }
			 
			 var data={
				 "novelId":$(".novelId").val(),
				 "authorId":$(".authorId").val(),
				 "cover":$(".cover").val(),
				 "introduce":$(".introduce").val(),
				 "sentiment":$(".sentiment").val(),
				 "collectionNumber":$(".collectionNumber").val(),
				 "novelName":$(".bookName").val(),
				 "createTime":timest(),
				 "categories":types
			 }
			 
			 var index = layer.load(0, {shade: false}); 
			 console.log(data)
			 
			 Vue.http.post(global_url+'/admin/novel/add/',data).then(
			 response=>{
			 	layer.close(index);
			 	layer.closeAll("iframe");
			 	//刷新父页面
			 	parent.location.reload();
			 },
			 response=>{
				 notice.init({
				 	type: "danger",
				 	autoClose: true,
				 	title: "请求失败",
				 	desktop: true,
				 });
			 	layer.close(index);
			 })
			
			return false
			 
			 
    })
	


		
		//刷新表单的复选框
		setTimeout(function(){
				form.render('checkbox',"bookinfopage");
		},100);

})

